<template>
  <common-page title="政务服务文件列表">
    <avue-crud
      ref="crud"
      v-model="form"
      class="crud-table"
      :option="tableOption"
      :data="list"
      :page.sync="page"
      :search.sync="searchForm"
      :table-loading="loading"
      :header-cell-class-name="() => 'crud-table-head'"
      :cell-class-name="() => 'crud-cell'"
      @search-change="searchChange"
      @refresh-change="getList()"
      @hook:mounted="$ele.tableMount($refs.crud)"
      @hook:beforeDestroy="$ele.tableDestroy($refs.crud)"
      @current-change="currentChange"
      @size-change="handleSizeChange"
    >
      <template #menuLeft>
        <el-button type="primary" @click="handleExport" :loading="isUpload">导出</el-button>
      </template>
      <template #tonRangeSearch>
        <div style="display: flex">
          <el-input-number
            v-model.trim="searchForm.startTotalTon"
            controls-position="right"
            :min="0"
            :max="searchForm.endTotalTon ? searchForm.endTotalTon : 999999999"
            clearable
          ></el-input-number>
          <span style="margin: 0 10px">至</span>
          <el-input-number
            v-model.trim="searchForm.endTotalTon"
            controls-position="right"
            :min="searchForm.startTotalTon ? searchForm.startTotalTon : 0"
            :max="999999999"
            clearable
          ></el-input-number>
        </div>
      </template>
      <template #searchMenu="{ size }">
        <el-button type="primary" :size="size" @click="searchChange">查 询 </el-button>
        <el-button type="primary" plain :size="size" @click="resetForm">重 置 </el-button>
      </template>
      <template #menu>
        <el-button type="text" @click="() => (dialogVisible = true)">续期</el-button>
        <el-button type="text" @click="()=>dialogVisible1 = true">失效</el-button>
        <el-button type="text" @click="()=>dialogVisible2 = true">清理</el-button>
        <el-button type="text" @click="()=>dialogVisible3 = true">记录</el-button>

      </template>
    </avue-crud>
    <el-dialog title="续期" :visible.sync="dialogVisible" width="30%" custom-class="crud-dialog" :before-close="() => (dialogVisible = false)">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="时间">
          <el-date-picker v-model="form.value1" type="date" placeholder="选择日期"> </el-date-picker>
        </el-form-item>
        <el-form-item label="理由">
          <el-input type="textarea" v-model="form.desc"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="失效" :visible.sync="dialogVisible1" width="30%" custom-class="crud-dialog" :before-close="() => (dialogVisible1 = false)">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="废止理由">
          <el-input type="textarea" v-model="form.desc"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible1 = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible1 = false">确 定</el-button>
      </span>
    </el-dialog>
    <!--  -->
    <el-dialog title="清理" :visible.sync="dialogVisible2" width="30%" custom-class="crud-dialog" :before-close="() => (dialogVisible2 = false)">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="是否确认">
          <el-radio v-model="radio" label="1">确认</el-radio>
  <el-radio v-model="radio" label="2">回退</el-radio>
        </el-form-item>
        <el-form-item label="意见">
          <el-input type="textarea" v-model="form.desc"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible2 = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible2 = false">确 定</el-button>
      </span>
    </el-dialog>
    <!--  -->
    <el-dialog title="记录" :visible.sync="dialogVisible3" width="50%" custom-class="crud-dialog" :before-close="() => (dialogVisible3 = false)">
      <avue-crud
      ref="crud"
      v-model="form"
      class="crud-table"
      :option="options1"
      :data="list1"
      :page.sync="page"
      :search.sync="searchForm"
      :table-loading="loading"
      :header-cell-class-name="() => 'crud-table-head'"
      :cell-class-name="() => 'crud-cell'"
      @search-change="searchChange"
      @refresh-change="getList()"
      @hook:mounted="$ele.tableMount($refs.crud)"
      @hook:beforeDestroy="$ele.tableDestroy($refs.crud)"
      @current-change="currentChange"
      @size-change="handleSizeChange"
    >
    </avue-crud>
    </el-dialog>
  </common-page>
</template>

<script>
import { options1, tableOption } from './tableOption'
import fileDownload from 'js-file-download'
export default {
  data() {
    return {
      dialogVisible: false,
      dialogVisible1: false,
      dialogVisible2:false,
      dialogVisible3:false,

      form:{},
      searchForm: {},
      isUpload: false,
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      list: [],
      list1:[
        {p1:'文件A',p2:'1.o.o',p3:'发布',p4:'2025-9-8',p5:'部门A',p6:'张三',p7:'文件G'},
        {p1:'文件A',p2:'1.o.o',p3:'发布',p4:'2025-9-8',p5:'部门A',p6:'张三',p7:'文件G'},

        {p1:'文件A',p2:'1.o.o',p3:'发布',p4:'2025-9-8',p5:'部门A',p6:'张三',p7:'文件G'}

      ],

      loading: true,
      form: {},
      shipTypeArr: [], // 船舶类型
      shipSTypeArr: [],
      homePortArr: [], // 船籍港
      registArr: [] // 登记机构
    }
  },
  computed: {
    tableOption() {
      return tableOption.call(this)
    },
    options1(){
      return options1.call(this)
    },
    documentHeight() {
      return this.$store.state.app.documentClientHeight
    }
  },
  created() {
    this.getList()
  },
  methods: {
    resetForm() {
      this.$refs.crud.searchReset()
      this.page.currentPage = 1
      this.getList()
    },

    getList() {
      this.loading = false
      this.list = [
        { p1: '文件1', p2: '问号222', p3: '部门A', p4: '范围', p5: '2024-8-9', p6: '2024-8-9', p7: '过期' },
        { p1: '文件1', p2: '问号222', p3: '部门A', p4: '范围', p5: '2024-8-9', p6: '2024-8-9', p7: '过期' },

        { p1: '文件1', p2: '问号222', p3: '部门A', p4: '范围', p5: '2024-8-9', p6: '2024-8-9', p7: '过期' }
      ]
      this.page.total = 10
    },
    currentChange(val) {
      this.page.currentPage = val
      this.getList()
      this.$refs.curd?.doLayout()
    },
    handleSizeChange(val) {
      this.page.pageSize = val
      this.getList()
      this.$refs.curd.doLayout()
    },
    searchChange(form, done) {
      this.page.currentPage = 1
      this.getList()
      done && done()
    },
    // 船舶类型
    async getShipArr() {
      let { result } = await getDict('ship_type')
      this.shipTypeArr = result
      let { result: s } = await getDict('ship_large_type')
      this.shipSTypeArr = s
    },
    // 船籍港
    async getHomePortArr() {
      let { result } = await getDictByHome()
      this.homePortArr = result
    },
    // 登记机构
    async getRegistArr() {
      let { result } = await getDictByRegist()
      this.registArr = this.getPortData(result)
    },
    getPortData(data) {
      for (var i = 0; i < data.length; i++) {
        if (data[i].children) {
          if (data[i].children.length < 1) {
            data[i].children = undefined
          } else {
            this.getPortData(data[i].children)
          }
        }
      }
      return data
    },
    // 导出
    async handleExport() {
      this.isUpload = true
      this.axios({
        url: '/api/supervise/tenant/export',
        methods: 'get',
        responseType: 'blob',
        params: this.searchForm,
        headers: {
          Authorization: `bearer ${window.$auth.getToken()}`
        }
      })
        .then((res) => {
          this.isUpload = false
          fileDownload(res.data, `监管船舶信息表.xls`)
        })
        .catch(() => {
          this.isUpload = false
        })
    },
    handle1() {
      this.$confirm('是否确认审核?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {})
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    handle2() {
      this.dialogVisible = true
    },
    handle3() {
      this.$confirm('设置?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {})
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    }
  }
}
</script>
<style scoped lang="scss"></style>
